package com.tsxy.controller.administrator;

import com.tsxy.common.APIResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.tsxy.service.IBookPictureRelationService;
import com.tsxy.entity.BookPictureRelation;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 飞
 * @since 2022-03-05
 */
@RestController
@RequestMapping("/book-picture-relation")
public class BookPictureRelationController {

    @Resource
    private IBookPictureRelationService bookPictureRelationService;

    //新增或者修改
    @PostMapping
    public APIResult save(@RequestBody BookPictureRelation bookPictureRelation){
        return APIResult.success(bookPictureRelationService.saveOrUpdate(bookPictureRelation));
    }
    //根据id删除
    @DeleteMapping("/{id}")
    public APIResult delete(@PathVariable Integer id) {
        return APIResult.success(bookPictureRelationService.removeById(id));
    }
    //批量删除
    @PostMapping("/del/batch")
        public APIResult deleteBath(@RequestBody List<Integer> ids){
        return APIResult.success(bookPictureRelationService.removeByIds(ids));
    }
    //查询所有
    @GetMapping
    public APIResult findAll() {
        return APIResult.success(bookPictureRelationService.list());
    }
    //根据id查询
    @GetMapping("/{id}")
        public APIResult findOne(@PathVariable Integer id) {
        return APIResult.success(bookPictureRelationService.getById(id));
    }
    //分页查询
    @GetMapping("/page")
    public APIResult findPage(@RequestParam Integer pageNum,
                    @RequestParam Integer pageSize) {
        QueryWrapper<BookPictureRelation> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return APIResult.success(bookPictureRelationService.page(new Page<>(pageNum,pageSize), queryWrapper));
    }



}

